package baidumapsdk.demo;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class chenchenDemo extends Activity{

	// 定位相关
	LocationClient mLocClient;// 定位客户端
	public MyLocationListenner myListener = new MyLocationListenner();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chenchen);
		
        //定位初始化
		mLocClient = new LocationClient(this);
		mLocClient.registerLocationListener(myListener);
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(true);// 打开gps
		option.setCoorType("bd09ll"); // 设置坐标类型
		option.setScanSpan(5000);//设置扫描间隔，单位是毫秒 当<1000(1s)时，定时定位无效
		mLocClient.setLocOption(option);
		mLocClient.start();
	}
	/**
	 * 定位SDK监听函数
	 */
	public class MyLocationListenner implements BDLocationListener {

		@Override
		public void onReceiveLocation(BDLocation location) {
			// map view 销毁后不在处理新接收的位置
			if (location == null )
				return;
			String LocString="纬度："+location.getLatitude()+"     经度："+location.getLongitude();
			Log.i("LTAG",LocString);
			Toast.makeText(chenchenDemo.this,LocString ,Toast.LENGTH_SHORT).show();
		}

		public void onReceivePoi(BDLocation poiLocation) {
		}
	}

//	@Override
//	protected void onPause() {
//		super.onPause();
//	}
//
//	@Override
//	protected void onResume() {
//		super.onResume();
//	}
//
//	@Override
//	protected void onDestroy() {
//		// 退出时销毁定位
//		mLocClient.stop();
//		// 关闭定位图层
//		super.onDestroy();
//	}
}
